Analysis of Spatial Data

We are going to analyze an invasive ductal carcinoma breast tissue section from 10x Genomicsis Visium Gene Expression platform.

For the analysis we will mainly use the R package Seurat.

Download Data

You can download the data from this website or using curl, as shown below. We do not need to do it because it is already in the data folder.

# download files
curl -O https://cf.10xgenomics.com/samples/spatial-exp/1.1.0/V1_Breast_Cancer_Block_A_Section_1/V1_Breast_Cancer_Block_A_Section_1_filtered_feature_bc_matrix.h5
curl -O https://cf.10xgenomics.com/samples/spatial-exp/1.1.0/V1_Breast_Cancer_Block_A_Section_1/V1_Breast_Cancer_Block_A_Section_1_spatial.tar.gz

Libraries

These are the libraries we are going to use:

library(tidyverse)
library(Seurat)
library(patchwork)
# set seed for reproducibility purposes
set.seed(1243)
# create palette for the cell types from the pals package
cell_type_palette <- c(
  "#5A5156", "#E4E1E3", "#F6222E", "#FE00FA",
  "#16FF32", "#3283FE", "#FEAF16", "#B00068",
  "#1CFFCE", "#90AD1C", "#2ED9FF", "#DEA0FD",
  "#AA0DFE", "#F8A19F", "#325A9B", "#C4451C",
  "#1C8356", "#85660D", "#B10DA1", "#FBE426",
  "#1CBE4F", "#FA0087", "#FC1CBF", "#F7E1A0",
  "#C075A6", "#782AB6", "#AAF400", "#BDCDFF",
  "#822E1C", "#B5EFB5", "#7ED7D1", "#1C7F93",
  "#D85FF7", "#683B79", "#66B0FF", "#3B00FB")

Load data with Seurat

We start by loading the data Visium data. Note that here we start by already loading the filtered expression data. This means that we are only keeping those spots that overlap with the tissue as determined by spaceranger.

If we expect there to be overpermabilization of the tissue or want to get a more general look we can load the raw HDF5 file instead. The raw file contains the matrix for all 5.000 spots comprising the capture area.

sp_obj <- Load10X_Spatial(
  data.dir = "data", # Directory where these data is stored
  filename = "filtered_feature_bc_matrix.h5", # Name of H5 file containing the feature barcode matrix
  assay = "Spatial", # Name of assay
  slice = "slice1",   # Name of the image
  filter.matrix = TRUE # Only keep spots that have been determined to be over tissue
  )

The visium data from 10x consists is stored in a Seurat object. This object has a very similar structure to the scRNAseq object:

  • A spot x gene expression matrix (similar to the cell x gene matrix)
sp_obj[["Spatial"]][1:5, 1:5]
## 5 x 5 sparse Matrix of class "dgCMatrix"
##             AAACAAGTATCTCCCA-1 AAACACCAATAACTGC-1 AAACAGAGCGACTCCT-1
## MIR1302-2HG                  .                  .                  .
## FAM138A                      .                  .                  .
## OR4F5                        .                  .                  .
## AL627309.1                   .                  .                  .
## AL627309.3                   .                  .                  .
##             AAACAGGGTCTATATT-1 AAACAGTGTTCCTGGG-1
## MIR1302-2HG                  .                  .
## FAM138A                      .                  .
## OR4F5                        .                  .
## AL627309.1                   .                  .
## AL627309.3                   .                  .
  • H&E Image of the tissue slice (obtained from staining during sample processing in the lab)

It adds one slot which contains the images of the Visium experiments as seen below:

sp_obj@images
## $slice1
## Spatial data from the VisiumV1 technology for 3798 samples
## Associated assay: Spatial 
## Image key: slice1_

We can visualize the image as follows (we will also store this for later):

(img <- SpatialPlot(
  sp_obj, # Name of the Seurat Object
  pt.size = 0, # Point size to see spots on the tissue
  crop = FALSE # Wether to crop to see only tissue section
  ) + 
  NoLegend()
)

  • Scaling factors that relate the original high resolution image to the lower resolution image used here for visualization.
sp_obj@images$slice1@scale.factors
## $spot
## [1] 0.08250825
## 
## $fiducial
## [1] 286.7012
## 
## $hires
## [1] 0.08250825
## 
## $lowres
## [1] 0.02475247
## 
## attr(,"class")
## [1] "scalefactors"

Quality control

The goal of this step is to remove poor quality spots and lowly captured genes. To do so we will go over some basic QC steps. Furthermore, due to the nature of the assay during library preparation there can be some lateral diffusion of transcripts. If there are spots not overlapping with the tissue we also need to remove them since these are artifacts of the experiment.

As with single-cell objects, we have some important features that we can use to filter out bad quality spots.

  • nCount_Spatial: number of UMIs per spot
umi_vln_plt <- VlnPlot(
  sp_obj, 
  features = "nCount_Spatial", 
  pt.size = 0.1) + 
  NoLegend()
umi_sp_plt <- SpatialFeaturePlot(
  sp_obj, 
  features = "nCount_Spatial")
umi_vln_plt | umi_sp_plt | img

The variability in the distribution of UMIs is related to the tissue architecture, i.e. tumoral regions have a higher cell density than fibrotic regions and thus overlapping spots contain higher counts.

  • nFeature_Spatial: number of genes per spot
feat_vln_plt <- VlnPlot(
  sp_obj, 
  features = "nFeature_Spatial", 
  pt.size = 0.1) + 
  NoLegend()
feat_sp_plt <- SpatialFeaturePlot(
  sp_obj, 
  features = "nFeature_Spatial")
feat_vln_plt | feat_sp_plt | img

Again, here we can see how the number of genes per spot correlates with the structure of the tissue.

  • mt.content and rb.content: mitochondrial and ribosomal content per spot, respectively

We have to compute this two values by calculating the percentage of reads per spot that belong to mitochondrial/ribosomal genes.

# Mitochondrial content
sp_obj[["mt.content"]] <- PercentageFeatureSet(
  object = sp_obj,
  pattern = "^MT-")
summary(sp_obj[["mt.content"]])
##    mt.content    
##  Min.   : 1.118  
##  1st Qu.: 2.761  
##  Median : 3.504  
##  Mean   : 4.009  
##  3rd Qu.: 4.678  
##  Max.   :14.415
# Ral contentibosomal
sp_obj[["rb.content"]] <- PercentageFeatureSet(
  object = sp_obj,
  pattern = "^RPL|^RPS")
summary(sp_obj[["rb.content"]])
##    rb.content    
##  Min.   : 6.697  
##  1st Qu.:10.765  
##  Median :11.752  
##  Mean   :11.958  
##  3rd Qu.:12.923  
##  Max.   :21.482
SpatialFeaturePlot(
  sp_obj, 
  features = c("mt.content", "rb.content"))

In the case of spatial data, high mitochondrial content is not necessarily an indicator of bad quality spots. Therefore, on its own it is not sufficient to determine which spots to filter out. In this case, they are not pointing towards low quality regions but seem to be reflecting the biological structure of the tissue.

Gene filtering

Before filtering:

sp_obj
## An object of class Seurat 
## 36601 features across 3798 samples within 1 assay 
## Active assay: Spatial (36601 features, 0 variable features)

We are going to filter out genes that have no expression in the tissue.

table(rowSums(as.matrix(sp_obj@assays$Spatial@counts)) == 0)
## 
## FALSE  TRUE 
## 24923 11678
keep_genes <- rowSums(as.matrix(sp_obj@assays$Spatial@counts)) != 0
sp_obj <- sp_obj[keep_genes, ]

We see how we remove 11.678 genes while keeping 24.923.

Spot filtering

Furthermore, we set a threshold to filter out spots with very low number of counts (< 500) before proceeding with the downstream analysis. As we can see there are no spots with <500 UMIs so we will not remove any of them.

table(colSums(as.matrix(sp_obj@assays$Spatial@counts)) < 500)
## 
## FALSE 
##  3798
sp_obj <- subset(
  sp_obj,
  subset = nCount_Spatial > 500)

After filtering:

sp_obj
## An object of class Seurat 
## 24923 features across 3798 samples within 1 assay 
## Active assay: Spatial (24923 features, 0 variable features)

Preprocessing

Similar to single-cell datasets, preprocessing for spatial data requires normalization, identification of variable features and scaling the counts. To carry out these steps we will use SCTransform which takes into account that different spot complexities observed. Spots overlapping more cell-dense regions will have more UMIs. If we use standard Log Normalization we are removing this biological signal from the dataset.

sp_obj <- SCTransform(
  sp_obj,
  assay = "Spatial", # assay to pull the count data from
  ncells = ncol(sp_obj), # Number of subsampling Spots used to build NB regression, in this case use all
  variable.features.n = 3000,  # variable features to use after ranking by residual variance
  verbose = FALSE
  )

Prior to clustering, we perform dimensionality reduction via PCA. We then look at the elbow plot to assess the right number of principal components (PC) to use for downstream analysis.

sp_obj <- RunPCA(
  sp_obj, 
  npcs = 50
  )
ElbowPlot(
  sp_obj, 
  ndims = 50
  )

We see an elbow at 15 PC, after that the standard deviations are pretty much flat indicating that they aren’t contributing much information. To reduce computational resources and noise we proceed with the first 15 PCs and add another 10 for a total of 25 PCs to make sure we are not loosing biological signal while reducing the noise.

sp_obj <- RunUMAP(
  sp_obj,
  reduction = "pca",
  dims = 1:25
  )

Clustering and visualization

Next we compute the K nearest neighbors and find an optimal number of clusters using shared nearest neighbor Louvain modularity based clustering.

sp_obj <- FindNeighbors(
  sp_obj, 
  reduction = "pca", 
  dims = 1:20
  )
sp_obj <- FindClusters(
  sp_obj,
  resolution = 0.3
  )
## Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
## 
## Number of nodes: 3798
## Number of edges: 124079
## 
## Running Louvain algorithm...
## Maximum modularity in 10 random starts: 0.9250
## Number of communities: 9
## Elapsed time: 0 seconds

Look at the clustering in the UMAP space and on the tissue:

umap_plt <- DimPlot(
  sp_obj, 
  label = TRUE
  )
sp_plt <- SpatialDimPlot(
  sp_obj
  ) +
  NoLegend()
umap_plt + sp_plt

Gene expression and annotation

ESR1 and ERBB2 (HER2) are the two of the most common mutations in breast cancer, so one way of annotating the tissue is by looking at ESR1 and ERBB2 positive/negative regions.

SpatialFeaturePlot(
  sp_obj, 
  features = c("ESR1", "ERBB2"), 
  alpha = c(0.1, 1)
  ) + 
  (SpatialDimPlot(
    sp_obj,
    label = TRUE
    ) +
  NoLegend())

From the expression of the two genes above we can do a high-level annotation.

sp_obj@meta.data <- sp_obj@meta.data %>%
  mutate(annotation = case_when(
    SCT_snn_res.0.3 == 0 ~ "Fibrotic",
    SCT_snn_res.0.3 == 1 ~ "Fibrotic",
    SCT_snn_res.0.3 == 2 ~ "HER2-/ESR1-",
    SCT_snn_res.0.3 == 3 ~ "HER2-/ESR1+",
    SCT_snn_res.0.3 == 4 ~ "HER2+/ESR1+",
    SCT_snn_res.0.3 == 5 ~ "HER2+/ESR1-",
    SCT_snn_res.0.3 == 6 ~ "HER2-/ESR1-",
    SCT_snn_res.0.3 == 7 ~ "HER2-/ESR1-",
    SCT_snn_res.0.3 == 8 ~ "HER2-/ESR1-")
    )

Look at the annotation

# We will define a palette (this is optional)
annot_pal <- c("#ffb6db", "#004949", "#490092", "#920000", "#db6d00")
names(annot_pal) <- c("Fibrotic", "HER2-/ESR1-", "HER2-/ESR1+", "HER2+/ESR1-", "HER2+/ESR1+")
SpatialDimPlot(
  sp_obj,
  group.by = "annotation",
  cols = annot_pal
  )

Deconvolution

We are going to use SPOTlight in conjunction with a subset of the Tumor Immune Cell Atlas to deconvolute our spots and map immune populations to our tumor section.

# load library
library(SPOTlight)
library(NMF)

Load downsampled version of the Tumor Immune Cell Atlas and explore the metadata we have. We are going to use annotation level 1 for the deconvolution (lv1_annot). Moreover, since the origin of these cells is from different organs and papers we want to minize batch effect. To do so we will only select cells coming from one cancer type which has enough cells for all cell types.

atlas <- readRDS("R_obj/TICAtlas_downsample.rds")
head(atlas@meta.data)
##                patient nCount_RNA nFeature_RNA percent.mt  gender subtype
## MEL2_2_W461993  MEL2_2       1007          523  10.317460 unknown      CM
## MEL2_2_W462036  MEL2_2       1790          797  11.607143 unknown      CM
## MEL2_2_W462040  MEL2_2        905          498  13.480663 unknown      CM
## MEL2_2_W462050  MEL2_2       1113          669   7.726864 unknown      CM
## MEL2_2_W462065  MEL2_2        750          399  10.933333 unknown      CM
## MEL2_2_W462066  MEL2_2        815          436   7.239264 unknown      CM
##                   source           lv1_annot                    lv2_annot
## MEL2_2_W461993 melanoma2       T cells naive        CD4 memory stem cells
## MEL2_2_W462036 melanoma2       T cells naive        CD4 memory stem cells
## MEL2_2_W462040 melanoma2       CD8 cytotoxic                CD8 cytotoxic
## MEL2_2_W462050 melanoma2      T helper cells CD4 resident effector memory
## MEL2_2_W462065 melanoma2 CD4 effector memory                CD8 cytotoxic
## MEL2_2_W462066 melanoma2 CD8 effector memory                CD8 cytotoxic
table(atlas@meta.data$lv1_annot)
## 
##                  B cells      CD4 effector memory         CD4 naive-memory 
##                      100                      100                      100 
##   CD4 recently activated  CD4 transitional memory            CD8 cytotoxic 
##                      100                      100                      100 
##      CD8 effector memory        CD8 pre-exhausted CD8 terminally exhausted 
##                      100                      100                      100 
##                      cDC         Macrophages SPP1                      mDC 
##                      100                      100                      100 
##                Monocytes                       NK                      pDC 
##                      100                      100                      100 
##           Plasma B cells            Proliferative            T cells naive 
##                      100                      100                      100 
##       T cells regulatory           T helper cells                TAMs C1QC 
##                      100                      100                      100 
##      TAMs proinflamatory 
##                      100

Marker genes

First of all we need to compute the markers for the cell types using Seurat’s function FindAllMarkers.

Idents(atlas) <- "lv1_annot"
  
sc_markers <- FindAllMarkers(
  object = atlas,
  assay = "RNA",
  slot = "data",
  only.pos = TRUE
  )

saveRDS(sc_markers, "R_obj/filtered_atlas_markers.rds")
sc_markers <- readRDS("R_obj/filtered_atlas_markers.rds")
sc_markers %>%
  group_by(cluster) %>% 
  top_n(5, wt = avg_log2FC) %>% 
  DT::datatable()

Run Deconvolution

Run the deconvolution using the scRNAseq atlas and the spatial transcriptomics data.

decon_mtrx_ls <- spotlight_deconvolution(
  se_sc = atlas, # Single-cell dataset
  counts_spatial = sp_obj@assays$Spatial@counts,
  clust_vr = "lv1_annot", # Label to use for the deconvolution (cell types)
  cluster_markers = sc_markers, # Cell type markers
  hvg = 3000, # Number of HVGs to use on top of the markers
  min_cont = 0, # minimum expected contribution per cell type and spot
  assay = "RNA",
  slot = "counts"
  )

saveRDS(decon_mtrx_ls, "R_obj/deconvolution_ls.rds")
decon_mtrx_ls <- readRDS("R_obj/deconvolution_ls.rds")

Deconvolution assesment

Before even looking at the decomposed spots we can gain insight on how well the model performed by looking at the topic profiles for the cell types.

nmf_mod <- decon_mtrx_ls[[1]]
decon_mtrx <- decon_mtrx_ls[[2]]
rownames(decon_mtrx) <- colnames(sp_obj)
# info on the NMF model
nmf_mod[[1]]
## <Object of class: NMFfit>
##  # Model:
##   <Object of class:NMFns>
##   features: 3480 
##   basis/rank: 22 
##   samples: 2200 
##   theta: 0.5 
##  # Details:
##   algorithm:  nsNMF 
##   seed:  NMF 
##   RNG: 10403L, 624L, ..., -689249108L [e0d3d05f1b721ce7d02aa5d9b936a60e]
##   distance metric:  'KL' 
##   residuals:  3563528 
##   Iterations: 2000 
##   Timing:
##      user  system elapsed 
##   1993.28    7.72 2002.77
# deconvolution matrix
head(decon_mtrx)
##                        B.cells CD4.effector.memory CD4.naive.memory
## AAACAAGTATCTCCCA-1 0.010137316        2.337821e-17       0.08600150
## AAACACCAATAACTGC-1 0.011896373        2.733968e-02       0.11147947
## AAACAGAGCGACTCCT-1 0.038056501        4.511822e-17       0.19188749
## AAACAGGGTCTATATT-1 0.059475727        5.644065e-02       0.20056665
## AAACAGTGTTCCTGGG-1 0.008844078        5.507314e-02       0.05713598
## AAACATTTCCCGGATT-1 0.015016215        5.809065e-02       0.01998702
##                    CD4.recently.activated CD4.transitional.memory CD8.cytotoxic
## AAACAAGTATCTCCCA-1             0.02754046              0.06505139    0.02538960
## AAACACCAATAACTGC-1             0.17362920              0.05881900    0.05766773
## AAACAGAGCGACTCCT-1             0.19681667              0.15305800    0.00000000
## AAACAGGGTCTATATT-1             0.11554120              0.04922768    0.14375044
## AAACAGTGTTCCTGGG-1             0.15684167              0.03793254    0.08376386
## AAACATTTCCCGGATT-1             0.20397762              0.05225016    0.04142339
##                    CD8.effector.memory CD8.pre.exhausted
## AAACAAGTATCTCCCA-1          0.08938036       0.000000000
## AAACACCAATAACTGC-1          0.15701319       0.015386639
## AAACAGAGCGACTCCT-1          0.04832925       0.059781263
## AAACAGGGTCTATATT-1          0.05641382       0.012147690
## AAACAGTGTTCCTGGG-1          0.10444017       0.003339111
## AAACATTTCCCGGATT-1          0.17134106       0.015946950
##                    CD8.terminally.exhausted         cDC Macrophages.SPP1
## AAACAAGTATCTCCCA-1               0.07805629 0.010078568        0.4082143
## AAACACCAATAACTGC-1               0.03765994 0.007942235        0.1799766
## AAACAGAGCGACTCCT-1               0.06779712 0.024202138        0.0000000
## AAACAGGGTCTATATT-1               0.08356837 0.029321452        0.0000000
## AAACAGTGTTCCTGGG-1               0.03099807 0.012654295        0.2463184
## AAACATTTCCCGGATT-1               0.03965314 0.007187891        0.2171855
##                            mDC   Monocytes         NK         pDC
## AAACAAGTATCTCCCA-1 0.002396415 0.021046132 0.03655861 0.008410512
## AAACACCAATAACTGC-1 0.006540093 0.014949579 0.01181640 0.009304769
## AAACAGAGCGACTCCT-1 0.006628213 0.040366698 0.02113192 0.015695482
## AAACAGGGTCTATATT-1 0.004340445 0.020529591 0.04323099 0.016729485
## AAACAGTGTTCCTGGG-1 0.006509693 0.005230682 0.01830138 0.009425111
## AAACATTTCCCGGATT-1 0.006827030 0.011141659 0.01349643 0.007538095
##                    Plasma.B.cells Proliferative T.cells.naive
## AAACAAGTATCTCCCA-1     0.01250217    0.01935377   0.006317957
## AAACACCAATAACTGC-1     0.01391179    0.03434166   0.010680207
## AAACAGAGCGACTCCT-1     0.02152306    0.00000000   0.002864956
## AAACAGGGTCTATATT-1     0.01215923    0.00000000   0.026097732
## AAACAGTGTTCCTGGG-1     0.01330315    0.04682918   0.017745900
## AAACATTTCCCGGATT-1     0.01436761    0.04330740   0.014661432
##                    T.cells.regulatory T.helper.cells  TAMs.C1QC
## AAACAAGTATCTCCCA-1         0.06032369     0.01155677 0.00000000
## AAACACCAATAACTGC-1         0.02565893     0.02467962 0.00000000
## AAACAGAGCGACTCCT-1         0.04413469     0.02156776 0.03151644
## AAACAGGGTCTATATT-1         0.02927158     0.01506484 0.01376969
## AAACAGTGTTCCTGGG-1         0.03612121     0.02281536 0.00000000
## AAACATTTCCCGGATT-1         0.02360271     0.01624148 0.00000000
##                    TAMs.proinflamatory       res_ss
## AAACAAGTATCTCCCA-1         0.021684185 5.217910e-05
## AAACACCAATAACTGC-1         0.009306901 5.202812e-02
## AAACAGAGCGACTCCT-1         0.014642352 7.086854e-33
## AAACAGGGTCTATATT-1         0.012352748 1.487515e-32
## AAACAGTGTTCCTGGG-1         0.026376988 7.714221e-02
## AAACATTTCCCGGATT-1         0.006756593 4.328916e-02

Look at how specific the topic profiles are for each cell type. Ideally we want to see how each cell type has its own unique topic profile. This means the model has learnt a unique gene signature for that cell type.

h <- NMF::coef(nmf_mod[[1]])
rownames(h) <- paste("Topic", 1:nrow(h), sep = "_")
topic_profile_plts <- SPOTlight::dot_plot_profiles_fun(
  h = h,
  train_cell_clust = nmf_mod[[2]])
topic_profile_plts[[2]]

We also want to take a look at the topic profiles of the individual cells. We want to see how all the cells from the same cell type share the same topic profiles to make sure the learned signature is robust. In this plot each facet shows all the cells from the same cell type.

topic_profile_plts[[1]] +
  theme(axis.text.x = element_blank())

Lastly we can take a look at which genes the model learned for each topic. Higher values indicate that the gene is more relevant for that topic. In the below table we can see how the top genes for topic 1 are characteristic for B cells (i.e. CD79A, CD79B, MS4A1, IGHD…).

sign <- basis(nmf_mod[[1]])
colnames(sign) <- paste0("Topic", seq_len(ncol(sign)))
# This can be dynamically visualized with DT as shown below
DT::datatable(sign, filter = "top")

Deconvolution visualization

Let’s now visualize how the deconvoluted spots on the the Seurat object.

# keep on
decon_mtrx <- decon_mtrx_ls[[2]]
decon_mtrx <- decon_mtrx[, colnames(decon_mtrx) != "res_ss"]
decon_mtrx <- decon_mtrx[, !is.na(colnames(decon_mtrx))]
# Set as 0 those cell types that contribute <3% to the spot
decon_mtrx[decon_mtrx < 0.02] <- 0
# Add deconvolution results to Seurat object
sp_obj@meta.data <- cbind(sp_obj@meta.data, decon_mtrx)
saveRDS(sp_obj, "R_obj/breast_slide_deconvoluted.rds")

We have an object with the deconvolution information already added:

sp_obj <- readRDS("R_obj/breast_slide_deconvoluted.rds")

The first thing we can do is look at the spatial scatterpie. This plot represents each spot as an individual piechart where the proportion of each cell type within that spot is represented.

ct <- colnames(decon_mtrx)
scatterpie_plot(
    se_obj = sp_obj,
    cell_types_all = ct,
    pie_scale = 0.3) +
  coord_fixed(ratio = 1) +
  scale_fill_manual(values = cell_type_palette)
## [1] "Using slice slice1"

As we can see when we look at all the cell types at the same time we are not able to discern clear patterns. To improve the visualization we will remove those cell types that are found in >80% of the spot and keep those that aren’t ubiquitouslyy expressed.

# keep only cell types that are present in less than 80% of the spots
keep_0.8 <- colSums(sp_obj@meta.data[, ct] > 0) < 0.8 * ncol(sp_obj)
# but not those that were not found on the tissue
keep_g0 <- colSums(sp_obj@meta.data[, ct] > 0) > 0
# select cell types fullfiling the conditions
ct_var <- colnames(sp_obj@meta.data[, ct])[keep_0.8 & keep_g0]
ct_var
##  [1] "B.cells"             "CD8.pre.exhausted"   "cDC"                
##  [4] "mDC"                 "Monocytes"           "NK"                 
##  [7] "pDC"                 "Plasma.B.cells"      "T.cells.naive"      
## [10] "T.cells.regulatory"  "T.helper.cells"      "TAMs.C1QC"          
## [13] "TAMs.proinflamatory"

Plot the spatial scatterpie only with the cell types of interest

scatterpie_plot(
  se_obj = sp_obj,
  cell_types_all = ct_var,
  pie_scale = 0.3) +
  coord_fixed(ratio = 1) +
  scale_fill_manual(values = cell_type_palette)
## [1] "Using slice slice1"

Next, we can visualize the individual cell type proportions on the spatial slide.

scaleFUN <- function(x) sprintf("%.2f", x)
SpatialPlot(
  object = sp_obj,
  features = ct,
  alpha = c(0, 1),
  ncol = 5, image.alpha = 0) &
  scale_fill_gradientn(
    colors = grDevices::heat.colors(10, rev = TRUE),
    # 2 decimals in the legend
    labels = scaleFUN,
    n.breaks = 4)

Lets now see the frequencies of selected cell types across the regions in the tissue. We will focus on pre-exhausted T cells and macrophages as they can give an idea of how infiltrated the tumor can be.

VlnPlot(
  sp_obj,
  features = c("Monocytes", "TAMs.C1QC", "TAMs.proinflamatory", "CD8.terminally.exhausted", "CD8.pre.exhausted"),
  group.by = "annotation",
  cols = annot_pal,
  pt.size = 0.5
  )

plt_annot <- SpatialDimPlot(
  sp_obj, 
  group.by = "annotation",
  cols = annot_pal
  )
img | plt_annot

We can see that in the HER2+/ESR1- (dark red) region we have an abundance of pre-exhausted CD8 T cells as well as pro-inflamatory macrophages. The presence of both subtypes at the same time in a tumor region, can be indicative of the presence of a highly infiltrated tumor, often referred to as a “hot” tumor.

This type of tumors often have a better response to treatment, opposite to cold regions, where little to no immune cells are able to infiltrate the tumor, conforming a immune excluded section, often linked to worse treatment response.


Back to top

sessionInfo()
## R version 4.1.0 (2021-05-18)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18363)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=Spanish_Spain.1252  LC_CTYPE=Spanish_Spain.1252   
## [3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C                  
## [5] LC_TIME=Spanish_Spain.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] imager_0.42.11      magrittr_2.0.1      cowplot_1.1.1      
##  [4] NMF_0.23.0          Biobase_2.53.0      BiocGenerics_0.40.0
##  [7] cluster_2.1.2       rngtools_1.5.2      pkgmaker_0.32.2    
## [10] registry_0.5-1      SPOTlight_0.1.7     patchwork_1.1.1    
## [13] SeuratObject_4.0.4  Seurat_4.0.6        forcats_0.5.1      
## [16] stringr_1.4.0       dplyr_1.0.7         purrr_0.3.4        
## [19] readr_2.1.1         tidyr_1.1.4         tibble_3.1.6       
## [22] ggplot2_3.3.5       tidyverse_1.3.1    
## 
## loaded via a namespace (and not attached):
##   [1] readxl_1.3.1          backports_1.4.1       plyr_1.8.6           
##   [4] igraph_1.2.10         lazyeval_0.2.2        splines_4.1.0        
##   [7] crosstalk_1.2.0       listenv_0.8.0         scattermore_0.7      
##  [10] gridBase_0.4-7        digest_0.6.29         foreach_1.5.1        
##  [13] htmltools_0.5.2       tiff_0.1-10           fansi_0.5.0          
##  [16] doParallel_1.0.16     tensor_1.5            ROCR_1.0-11          
##  [19] tzdb_0.2.0            globals_0.14.0        modelr_0.1.8         
##  [22] matrixStats_0.61.0    spatstat.sparse_2.1-0 jpeg_0.1-9           
##  [25] colorspace_2.0-2      rvest_1.0.2           ggrepel_0.9.1        
##  [28] haven_2.4.3           xfun_0.29             crayon_1.4.2         
##  [31] jsonlite_1.7.2        scatterpie_0.1.7      spatstat.data_2.1-2  
##  [34] iterators_1.0.13      survival_3.2-13       zoo_1.8-9            
##  [37] glue_1.6.0            polyclip_1.10-0       gtable_0.3.0         
##  [40] leiden_0.3.9          future.apply_1.8.1    abind_1.4-5          
##  [43] scales_1.1.1          DBI_1.1.2             miniUI_0.1.1.1       
##  [46] Rcpp_1.0.7            viridisLite_0.4.0     xtable_1.8-4         
##  [49] reticulate_1.22       spatstat.core_2.3-2   bit_4.0.4            
##  [52] DT_0.20               htmlwidgets_1.5.4     httr_1.4.2           
##  [55] RColorBrewer_1.1-2    ellipsis_0.3.2        ica_1.0-2            
##  [58] pkgconfig_2.0.3       farver_2.1.0          sass_0.4.0           
##  [61] uwot_0.1.11           dbplyr_2.1.1          deldir_1.0-6         
##  [64] utf8_1.2.2            tidyselect_1.1.1      labeling_0.4.2       
##  [67] rlang_0.4.12          reshape2_1.4.4        later_1.3.0          
##  [70] munsell_0.5.0         cellranger_1.1.0      tools_4.1.0          
##  [73] cli_3.1.0             generics_0.1.1        broom_0.7.10         
##  [76] ggridges_0.5.3        evaluate_0.14         fastmap_1.1.0        
##  [79] yaml_2.2.1            goftest_1.2-3         knitr_1.37           
##  [82] bit64_4.0.5           fs_1.5.2              fitdistrplus_1.1-6   
##  [85] RANN_2.6.1            readbitmap_0.1.5      pbapply_1.5-0        
##  [88] future_1.23.0         nlme_3.1-153          mime_0.12            
##  [91] ggrastr_1.0.1         xml2_1.3.3            hdf5r_1.3.5          
##  [94] compiler_4.1.0        rstudioapi_0.13       beeswarm_0.4.0       
##  [97] plotly_4.10.0         png_0.1-7             spatstat.utils_2.3-0 
## [100] reprex_2.0.1          tweenr_1.0.2          bslib_0.3.1          
## [103] stringi_1.7.6         highr_0.9             RSpectra_0.16-0      
## [106] lattice_0.20-45       Matrix_1.4-0          vctrs_0.3.8          
## [109] pillar_1.6.4          lifecycle_1.0.1       spatstat.geom_2.3-1  
## [112] lmtest_0.9-39         jquerylib_0.1.4       RcppAnnoy_0.0.19     
## [115] data.table_1.14.2     irlba_2.3.5           httpuv_1.6.4         
## [118] R6_2.5.1              promises_1.2.0.1      bmp_0.3              
## [121] KernSmooth_2.23-20    gridExtra_2.3         vipor_0.4.5          
## [124] parallelly_1.30.0     codetools_0.2-18      MASS_7.3-54          
## [127] assertthat_0.2.1      withr_2.4.3           sctransform_0.3.2    
## [130] mgcv_1.8-38           parallel_4.1.0        hms_1.1.1            
## [133] ggfun_0.0.4           grid_4.1.0            rpart_4.1-15         
## [136] rmarkdown_2.11        Cairo_1.5-12.2        Rtsne_0.15           
## [139] ggforce_0.3.3         shiny_1.7.1           lubridate_1.8.0      
## [142] ggbeeswarm_0.6.0